home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
vbbook13.zip
/
SOURCE.DOC
< prev
next >
Wrap
Text File
|
1993-04-04
|
21KB
|
592 lines
VB BOOK 1.0 Source Code
NOTE: This is older code so do NOT use this code to modify VB BOOK! It
is included here only to show people without Visual Basic what makes
VB BOOK click.
The Global form (VBBOOK.BAS):
-----------------------------
Type Flags 'Misc flag variables
CurDate As Integer
DoHeader As Integer
FileTitle As Integer
LineLen As Integer
LineWrap As Integer
PgNumber As Integer
End Type
'The VBBOOK.FRM form: (used for the first little box that goes away in 5 sec's.)
'--------------------
'(No code in this form. Just displays a message for 5 secs)
'The VBBOUT.FRM form:
'--------------------
'(No code in this form. It's a blank, full-page form used to cover up the
'desktop. There should be a better way to do this!)
'The Main module, VBBINP.FRM: (This is where all the selections are done.)
'----------------------------
'Declarations section:
'Note that Dim Shared is not really needed but VB done it during the automatic
'conversion from QuickBasic code so I left it that way.
Dim Shared ESC$, FF$, LF$, filename$, OUTFILE$, NL$
Dim Shared page%, num$, tune%
Dim Shared PC As Flags
Dim lastchange As Integer
Const fileboxclick = 0, dirsboxclick = 1 'Used by file selection routine
Const true = -1, false = 0
'Now the Subs start:
Static Sub BuildArray (ptrarray&(), pgcount%)
MaxLines% = 66 'Maximum number of lines
Offset& = 1 'Start of file (seek point)
Open filename$ For Binary Access Read As #1 Len = 1 'Open file to check
TotalSize& = LOF(1) 'Get LEN of file so we don't read too far
FileLeft& = TotalSize& 'Setup a counter to show whats left
'FRE is not supported by VB. Just set it to 64K
MemAvail& = 65536 'FRE(FileName$) - 2048 'Check available string memory
If MemAvail& < 2048 Then Error 14 'Force out of memory error
SixteenK% = 16384
If TotalSize& > SixteenK% Then 'Set a buffer size
If MemAvail& > SixteenK% Then 'If the file is larger than 16K
BufAvail& = SixteenK% 'Set it to 16k
Else
BufAvail& = MemAvail&
End If
Else
If TotalSize& < MemAvail& Then 'Otherwise set it to file size
BufAvail& = TotalSize&
End If
BuffSize% = BufAvail&
End If
pgcount% = 1 'Initialize page count
ptrarray&(pgcount%) = 1 'First pointer is always 1
LnCount% = 0 'Initialize line count
GetPage: 'Read the file
If FileLeft& < BufAvail& Then 'Check amount left to read
Buffer$ = Space$(FileLeft&) 'If less than our buffer, use lessor
Else
Buffer$ = Space$(BufAvail&) 'Otherwise use full buffer size
End If
Get #1, Offset&, Buffer$ 'Read in a buffers worth
stptr% = 1 'Pointer into buffer$
LastLine% = 0 'remember last position
PageCheck:
TempLn% = InStr(stptr%, Buffer$, LF$) 'Position of next linefeed
temppg% = InStr(stptr%, Buffer$, FF$) 'Position of next pagefeeds
If temppg% Then 'If there was a page feed
If temppg% < TempLn% Or TempLn% = 0 Then ' was it before our linefeed?
pgcount% = pgcount% + 1 ' yes then bump page count
ptrarray&(pgcount%) = Offset& + temppg% ' set next array element
stptr% = temppg% + 1 ' set instr pointer
LnCount% = 0 ' reset linecount
If stptr% < Len(Buffer$) Then GoTo PageCheck 'and loop back for more
End If
End If
If TempLn% Then 'Linefeed
If PC.LineWrap Then 'If Line Wrap, check length
If TempLn% - stptr% > PC.LineLen Then 'Greater than 80?
Do 'check for line wrap
LnCount% = LnCount% + 1 'increment line
If LnCount% = MaxLines% Then
GoTo PageBreak '> 66 lines
End If
stptr% = stptr% + PC.LineLen
Loop While TempLn% - stptr% > PC.LineLen
End If
End If
LnCount% = LnCount% + 1 'Increment page count
PageBreak:
If LnCount% = MaxLines% Then
pgcount% = pgcount% + 1
If pgcount% > 512 Then
msg$ = "Too may pages - printing only 512."
MsgBox msg$, 0, "Notice"
GoTo EndBuild
End If
ptrarray&(pgcount%) = Offset& + TempLn% 'point to next in point in file
LnCount% = 0
End If
stptr% = TempLn% + 1 'point ahead 1 byte for next scan
If stptr% <= Len(Buffer$) Then
GoTo PageCheck 'keep checking
End If
End If
Offset& = Offset& + Len(Buffer$) 'Pointer into file (tally)
stptr% = 1 'Reset Buffer pointer
FileLeft& = TotalSize& - Offset& 'Calculate how much is left
If Offset& < TotalSize& Then GoTo GetPage 'If more text in file, keep going
EndBuild:
ptrarray&(pgcount% + 1) = TotalSize& 'Set last pointer to end of file
Close #1 'Close input file
End Sub 'End of BuildArray Sub
Static Sub DoMacro (num$)
Print #2, ESC$; "&f"; num$; "y2X"; 'execute the macro
End Sub
Static Sub EndMacro (num$)
Print #2, ESC$; "&f"; num$; "y1X"; 'Send end of macro command
Print #2, ESC$; "&f"; num$; "y9X"; 'Make it temporary (10 to be permanent)
End Sub
Static Sub Header (page%)
hdr$ = Space$(PC.LineLen) 'Create a string to print
If PC.FileTitle Then 'Print the filename
Mid$(hdr$, 40 - Len(filename$) \ 2) = UCase$(filename$)
End If
If PC.PgNumber Then 'Print the current page
PTemp$ = "Page" + Str$(page%)
If page% Mod 2 Then
Mid$(hdr$, PC.LineLen - Len(PTemp$)) = PTemp$ 'odd page, right side
Else
Mid$(hdr$, 1) = PTemp$ 'even page, left side
End If
End If
If PC.CurDate Then 'Print the current date
If page% Mod 2 Then
Mid$(hdr$, 1) = Date$ 'even page, left side
Else
Mid$(hdr$, PC.LineLen - Len(Date$)) = Date$ 'odd page, right side
End If
End If
Print #2, hdr$ 'Print the Header
Print #2, ' and skip a line for readability
End Sub
Static Sub LJLocate (X%, Y%) 'Laser Jet cursor locate
Temp$ = ESC$ + "&a" + LTrim$(Str$(Y%)) + "r" + LTrim$(Str$(X%)) + "C"
Print #2, Temp$;
End Sub
Static Sub printlogo () 'Banner logo (About VB Box!)
msg$ = " VB Book" + NL$
msg$ = msg$ + " Converted to Visual Basic" + NL$
msg$ = msg$ + " by Dennis Scott." + NL$
msg$ = msg$ + NL$
msg$ = msg$ + "Send Comments/Suggestions to:" + NL$
msg$ = msg$ + " CompuDirect" + NL$
msg$ = msg$ + " 7711 Bulter Rd" + NL$
msg$ = msg$ + " Myrtle Beach, SC" + NL$
msg$ = msg$ + " (803)650-7452" + NL$
MsgBox msg$, 0, "About VB Book"
End Sub
Sub PrintSetup () 'Send codes to prepare printer
Print #2, ESC$; "E"; '